package cn.com.template.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

/**
 * 
 * 
 * @author Microbun 2012-2-14下午9:53:35
 * @version $Id$
 * @since 1.0
 */
@Controller
public class Demo {

	@RequestMapping("/gfx/{page}")
	public ModelAndView gfx(@PathVariable String page,
			HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mav = new ModelAndView("gfx/" + page);
		mav.addObject("aa", "dddd");
		return mav;
	}

	// @RequestMapping("/ajax/{name}")
	// public @ResponseBody
	// UserDO helloWorld(@PathVariable String name, HttpServletRequest request,
	// HttpServletResponse response) {
	// UserDO user = new UserDO();
	// user.setName(name);
	// user.setAge(18);
	// request.getServletContext();
	// return user;
	// }

	@RequestMapping("/fileupload")
	public ModelAndView fileupload(
			@RequestParam(value = "name", required = false) String name,
			@RequestParam(value = "file", required = false) MultipartFile file) {
		ModelAndView mav = new ModelAndView("fileupload");
		String msg = "";
		if (file != null) {
			if (!file.isEmpty()) {
				msg = "上传成功";
			} else {
				msg = "上传失败";
			}
			mav.addObject("msg", msg);
		}
		return mav;
	}

	public static void main(String[] args) {
		long startTime = System.currentTimeMillis();
		for (int i = 0; i < 10000000; i++) {
			new ModelAndView();
		}
		long endTime = System.currentTimeMillis();
		System.out.println((endTime - startTime) + "ms");
	}
}
